bindings: Support constants in IDL namespace (IDL parser) Makes IDL parser support constants in IDL namespaces. Change-Id: I7c078019ae2b1008d0569f91104d8a3c68c7a280 Bug: 1214607 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3279320 Commit-Queue: Yuki Shiino <yukishiino@chromium.org> Reviewed-by: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com> Cr-Commit-Position: refs/heads/main@{#941674} NOKEYCHECK=True GitOrigin-RevId: 36a95fa26422b2731903c72d1274af598351dc7e 
diff --git a/idl_parser.py b/idl_parser.py index 5ad38bd..91b988f 100755 --- a/idl_parser.py +++ b/idl_parser.py 
@@ -738,9 +738,12 @@  p[0] = self.BuildError(p, 'NamespaceMembers')    def p_NamespaceMember(self, p): - """NamespaceMember : ExtendedAttributeList ReturnType OperationRest - | ExtendedAttributeList READONLY AttributeRest""" - if p[2] != 'readonly': + """NamespaceMember : Const + | ExtendedAttributeList READONLY AttributeRest + | ExtendedAttributeList ReturnType OperationRest""" + if len(p) == 2: + p[0] = p[1] + elif p[2] != 'readonly':  applicable_to_types, non_applicable_to_types = \  DivideExtAttrsIntoApplicableAndNonApplicable(p[1])  if applicable_to_types: @@ -752,10 +755,11 @@  attributes = self.BuildProduction('ExtAttributes', p, 1,  non_applicable_to_types)  p[3].AddChildren(attributes) + p[0] = p[3]  else:  p[3].AddChildren(self.BuildTrue('READONLY'))  p[3].AddChildren(p[1]) - p[0] = p[3] + p[0] = p[3]    def p_Dictionary(self, p):  """Dictionary : DICTIONARY identifier Inheritance '{' DictionaryMembers '}' ';'""" 
diff --git a/test_parser/namespace_web.idl b/test_parser/namespace_web.idl index 06e42a4..bcffbd1 100644 --- a/test_parser/namespace_web.idl +++ b/test_parser/namespace_web.idl 
@@ -25,6 +25,9 @@    /** TREE  *Namespace(MyNamespace2) + * Const(FOO) + * PrimitiveType(long) + * Value() = "1"  * Operation(fooLong)  * Arguments()  * Type() @@ -38,6 +41,7 @@  * PrimitiveType(void)  */  namespace MyNamespace2 { + const long FOO = 1;  long fooLong();  void voidArgLong(long arg);  };